load("@rules_cc//cc:defs.bzl", "cc_library")

package(default_visibility = ["//visibility:public"])

cc_library(
    name = "platform-glfw",
    srcs = ["imgui_impl_glfw.cpp"],
    hdrs = ["imgui_impl_glfw.h"],
    include_prefix = "imgui",
    includes = ["."],
    linkopts = select({
        "@platforms//os:linux": [
            "-lpthread",
        ],
        "//conditions:default": [],
    }),
    # TODO: Remove this section after adding Windows support to @glfw:
    # https://registry.bazel.build/modules/glfw
    target_compatible_with = select({
        "@platforms//os:osx": [],
        "@platforms//os:linux": [],
        "//conditions:default": ["@platforms//:incompatible"],
    }),
    deps = [
        "//:imgui",
        "@glfw",
    ],
)

cc_library(
    name = "platform-win32",
    srcs = ["imgui_impl_win32.cpp"],
    hdrs = ["imgui_impl_win32.h"],
    include_prefix = "imgui",
    includes = ["."],
    target_compatible_with = [
        "@platforms//os:windows",
    ],
    deps = [
        "//:imgui",
    ],
)

cc_library(
    name = "renderer-opengl3",
    srcs = ["imgui_impl_opengl3.cpp"],
    hdrs = [
        "imgui_impl_opengl3.h",
        "imgui_impl_opengl3_loader.h",
    ],
    include_prefix = "imgui",
    includes = ["."],
    linkopts = select({
        "@rules_cc//cc/compiler:msvc-cl": [
            "/DEFAULTLIB:opengl32",
        ],
        "@rules_cc//cc/compiler:clang-cl": [
            "/DEFAULTLIB:opengl32",
        ],
        "@platforms//os:linux": [
            "-lGL",
            "-ldl",
        ],
        "//conditions:default": [],
    }),
    deps = [
        "//:imgui",
    ],
)

cc_library(
    name = "renderer-dx9",
    srcs = ["imgui_impl_dx9.cpp"],
    hdrs = ["imgui_impl_dx9.h"],
    include_prefix = "imgui",
    includes = ["."],
    linkopts = select({
        "@rules_cc//cc/compiler:msvc-cl": [
            "/DEFAULTLIB:D3D9",
        ],
        "@rules_cc//cc/compiler:clang-cl": [
            "/DEFAULTLIB:D3D9",
        ],
    }),
    target_compatible_with = [
        "@platforms//os:windows",
    ],
    deps = ["//:imgui"],
)

cc_library(
    name = "renderer-dx10",
    srcs = ["imgui_impl_dx10.cpp"],
    hdrs = ["imgui_impl_dx10.h"],
    include_prefix = "imgui",
    includes = ["."],
    linkopts = select({
        "@rules_cc//cc/compiler:msvc-cl": [
            "/DEFAULTLIB:D3D10",
        ],
        "@rules_cc//cc/compiler:clang-cl": [
            "/DEFAULTLIB:D3D10",
        ],
    }),
    target_compatible_with = [
        "@platforms//os:windows",
    ],
    deps = ["//:imgui"],
)

cc_library(
    name = "renderer-dx11",
    srcs = ["imgui_impl_dx11.cpp"],
    hdrs = ["imgui_impl_dx11.h"],
    include_prefix = "imgui",
    includes = ["."],
    linkopts = select({
        "@rules_cc//cc/compiler:msvc-cl": [
            "/DEFAULTLIB:D3D11",
        ],
        "@rules_cc//cc/compiler:clang-cl": [
            "/DEFAULTLIB:D3D11",
        ],
    }),
    target_compatible_with = [
        "@platforms//os:windows",
    ],
    deps = ["//:imgui"],
)

cc_library(
    name = "renderer-dx12",
    srcs = ["imgui_impl_dx12.cpp"],
    hdrs = ["imgui_impl_dx12.h"],
    include_prefix = "imgui",
    includes = ["."],
    linkopts = select({
        "@rules_cc//cc/compiler:msvc-cl": [
            "/DEFAULTLIB:D3D12",
            "/DEFAULTLIB:DXGI",
        ],
        "@rules_cc//cc/compiler:clang-cl": [
            "/DEFAULTLIB:D3D12",
            "/DEFAULTLIB:DXGI",
        ],
    }),
    target_compatible_with = [
        "@platforms//os:windows",
    ],
    deps = ["//:imgui"],
)
